package com.key.controller.admin.setting;

import com.key.common.R;
import com.key.common.vo.AreaPageVO;
import com.key.common.vo.AreaVO;
import com.key.entity.AssetType;
import com.key.entity.CArea;
import com.key.entity.PArea;
import com.key.service.AreaService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/*
 *
 * @author liu
 *
 */
@Controller
@RequestMapping("/area")
@Api(value = "区域管理",tags = "区域管理接口API")
public class AreaController {
    @Autowired
    private AreaService areaService;
    @RequestMapping(value = "/findAllArea",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "查询所有区域",notes = "查询省级区域表和县级区域表",httpMethod = "get", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="成功"),
            @ApiResponse(code=401,message="token为空"),
            @ApiResponse(code=1005,message="Token过期"),
            @ApiResponse(code=1006,message="Token验证不通过"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R findAllArea(){

        return areaService.findAllArea();
    }

    @RequestMapping(value = "/findAreaByPAreaName",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "选中分支查询",notes = "选中分支查询县级表",httpMethod = "post", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="成功"),
            @ApiResponse(code=401,message="token为空"),
            @ApiResponse(code=1005,message="Token过期"),
            @ApiResponse(code=1006,message="Token验证不通过"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R findAreaByPAreaName(@RequestBody @ApiParam(name = "areaPageVO",value = "区域分页",required = true) AreaPageVO areaPageVO){

        return areaService.findAreaByPAreaName(areaPageVO);
    }

    @RequestMapping(value = "/addPArea",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "添加省",notes = "添加数据到省级表",httpMethod = "post", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="成功"),
            @ApiResponse(code=401,message="token为空"),
            @ApiResponse(code=1005,message="Token过期"),
            @ApiResponse(code=1006,message="Token验证不通过"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R addPArea(@RequestBody  @ApiParam(name = "pArea",value = "省级区域实体",required = true)PArea pArea){
        return areaService.addPArea(pArea);
    }

    @RequestMapping(value = "/addCArea",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "添加县",notes = "添加数据到县级表",httpMethod = "post", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="成功"),
            @ApiResponse(code=401,message="token为空"),
            @ApiResponse(code=1005,message="Token过期"),
            @ApiResponse(code=1006,message="Token验证不通过"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R addCArea(@RequestBody  @ApiParam(name = "cArea",value = "县级区域实体",required = true)CArea cArea){

        return areaService.addCArea(cArea);
    }

    @RequestMapping(value = "/findAreaByCAreaName",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "查询框查询",notes = "根据区域名称查询县级表",httpMethod = "get", response = R.class)
    @ApiImplicitParam(name = "cAreaName",value = "县级区域名",paramType = "query",dataType = "String",required = true)
    @ApiResponses({
            @ApiResponse(code=200,message="成功"),
            @ApiResponse(code=401,message="token为空"),
            @ApiResponse(code=1005,message="Token过期"),
            @ApiResponse(code=1006,message="Token验证不通过"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R findAreaByCAreaName(@RequestParam("cAreaName") String cAreaName){

        return areaService.findAreaByCAreaName(cAreaName);
    }

    @RequestMapping(value = "/disableArea",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "禁用县级或省级区域",notes = "修改县级或省级区域状态",httpMethod = "post", response = R.class)
    @ApiImplicitParam(name = "id",value = "县级表id",paramType = "query",dataType = "int",required = true)
    @ApiResponses({
            @ApiResponse(code=200,message="成功"),
            @ApiResponse(code=401,message="token为空"),
            @ApiResponse(code=1005,message="Token过期"),
            @ApiResponse(code=1006,message="Token验证不通过"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R disableArea(@RequestParam("id") Integer id){

        return areaService.disableArea(id);
    }

    @RequestMapping(value = "/enableArea",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "解禁县级或省级区域",notes = "修改县级或省级区域状态",httpMethod = "post", response = R.class)
    @ApiImplicitParam(name = "id",value = "县级表id",paramType = "query",dataType = "int",required = true)
    @ApiResponses({
            @ApiResponse(code=200,message="成功"),
            @ApiResponse(code=401,message="token为空"),
            @ApiResponse(code=1005,message="Token过期"),
            @ApiResponse(code=1006,message="Token验证不通过"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R enableArea(@RequestParam("id") Integer id){

        return areaService.enableArea(id);
    }

    @RequestMapping(value = "/deleteArea",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "删除省级或县级区域",notes = "删除省级或县级表",httpMethod = "post", response = R.class)

    @ApiResponses({
            @ApiResponse(code=200,message="成功"),
            @ApiResponse(code=401,message="token为空"),
            @ApiResponse(code=1005,message="Token过期"),
            @ApiResponse(code=1006,message="Token验证不通过"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R deleteArea(@RequestBody @ApiParam(name = "ids",value = "县级表id集合",required = true) List<Integer> ids){

        return areaService.deleteArea(ids);
    }

    @RequestMapping(value = "/findCAreaById",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "查新县级区域",notes = "根据县级表主键查询",httpMethod = "get", response = R.class)
    @ApiImplicitParam(name = "id",value = "县级表id",paramType = "query",dataType = "int",required = true)
    @ApiResponses({
            @ApiResponse(code=200,message="成功"),
            @ApiResponse(code=401,message="token为空"),
            @ApiResponse(code=1005,message="Token过期"),
            @ApiResponse(code=1006,message="Token验证不通过"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R findCAreaById(@RequestParam("id")Integer id){

        return areaService.findCAreaById(id);
    }

    @RequestMapping(value = "/updateArea",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "编辑区域",notes = "修改省级区域表和县级区域表",httpMethod = "post", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="成功"),
            @ApiResponse(code=401,message="token为空"),
            @ApiResponse(code=1005,message="Token过期"),
            @ApiResponse(code=1006,message="Token验证不通过"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R updateArea(@RequestBody  @ApiParam(name = "cArea",value = "县区域实体",required = true)CArea cArea){

        return areaService.updateArea(cArea);
    }
}
